﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Globalization;

namespace SanctusSoftware.Music.Chords
{
    public static class UnicodeNormalizationHelper
    {

        public static string RemoveDiacritics(string stIn)
        {

            // http://blogs.msdn.com/michkap/archive/2007/05/14/2629747.aspx

            string stFormD = stIn.Normalize(NormalizationForm.FormD);
            StringBuilder sb = new StringBuilder();

            for (int ich = 0; ich < stFormD.Length; ich++)
            {
                UnicodeCategory uc = CharUnicodeInfo.GetUnicodeCategory(stFormD[ich]);
                if (uc != UnicodeCategory.NonSpacingMark)
                {
                    sb.Append(stFormD[ich]);
                }
            }

            string temp = (sb.ToString().Normalize(NormalizationForm.FormC));
            temp = temp.Replace("Ð", "D");
            return temp;
        }

        public static bool ContainsDiacritics(string s)
        {
            string temp = RemoveDiacritics(s);
            return (s != temp);
        }

    }
}
